package com.dkts.oil.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

/**
 * 文字转字符串类
 * @author heguanglong
 * @description: TODO
 * @date 2021/6/3
 */
public class FileToStringUtils {
    /**
     * 读取txt文件的内容
     *
     * @param file 想要读取的文件对象
     * @return 返回文件内容
     */
    public static String txt2String(File file) {
        StringBuilder result = new StringBuilder();
        try {
            BufferedReader br = new BufferedReader(new FileReader(file));
            String s = null;
            while ((s = br.readLine()) != null) {
                result.append(System.lineSeparator() + s);
            }
            br.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result.toString();
    }

}
